<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>web 存储</title>
</head>
<body>
<!--localStorage -->
<script type="text/javascript">

    if (localStorage.pagecount)
    {
        localStorage.pagecount=Number(localStorage.pagecount) +1;
    }
    else
    {
        localStorage.pagecount=1;
    }
    document.write("Visits: " + localStorage.pagecount + " time(s).");
    function clickCounter() {
        if(typeof(Storage) !== "undefined") {
            if (sessionStorage.clickcount) {
                sessionStorage.clickcount = Number(sessionStorage.clickcount)+1;
            } else {
                sessionStorage.clickcount = 1;
            }
            document.getElementById("result").innerHTML = "在本 session 中，您已经点击这个按钮 " + sessionStorage.clickcount + " 次。";
        } else {
            document.getElementById("result").innerHTML = "抱歉！您的浏览器不支持 Web Storage ...";
        }
    }
</script>

<p>刷新页面会看到计数器在增长。</p>

<p>请关闭浏览器窗口，然后再试一次，计数器会继续计数。</p>
<p><button onclick="clickCounter()" type="button">请点击这里</button></p>
<div id="result"></div>

<script>
    // Check browser support
    if (typeof(Storage) !== "undefined") {
        // Store
        localStorage.setItem("lastname", "Gates");
        // Retrieve
        document.getElementById("result").innerHTML = localStorage.getItem("lastname");
    } else {
        document.getElementById("result").innerHTML = "抱歉！您的浏览器不支持 Web Storage ...";
    }
</script>
</body>
</html>